package com.hh.game.service.gateway.filter.security;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hh.game.service.gateway.codec.Response;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class DefaultWebSocketSecurityManager implements SecurityManager {
    private HashSet<String> perms;

    public DefaultWebSocketSecurityManager() {
        perms = new HashSet<>();
        perms.add(SecurityEnum.LOGIN.name());
    }

    @Override
    public boolean login(Response response) {
        JSONObject obj = (JSONObject) JSON.toJSON(response.getResult());
        int code = obj.getIntValue("code");
        return code == 200;
    }

    @Override
    public Set<String> getPermission(Response response) {
        return perms;
    }
}
